package Test.code;

import java.io.File;
import java.io.FileWriter;

import Test.tools.Utils;


public class BeanGener  {

	  public static void beanTest(String tableName,String tableBean,String currentBao) throws  Exception{
		String rn = "\r\n";
		String []array = Utils.stringToArray(tableBean);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < array.length; i++) {
			String bean="";
			if(i == 0){
				bean=
					 rn +
					"     //属性：  "+ array[0] + "---" + rn +
					"     int " + array[0] + ";" + rn +
					rn +
					"     public int get" + Utils.upperFirstChar(array[0]) + "() {" + rn +
					"	       return " + array[0] + ";" + rn +
					"     }" + rn +
					 rn +
					"     public void set" + Utils.upperFirstChar(array[0]) + "(int  " + array[0] + ") {" + rn +
					"	       this. " + array[0] + " = " + array[0] + ";" + rn +
					"     }" + rn;
			}
			else{
				bean=
					 rn +
					"     //属性：  "+ array[i] + "---" + rn +
					"     String " + array[i] + ";" + rn +
					rn +
					"     public String get" + Utils.upperFirstChar(array[i]) + "() {" + rn +
					"	      return " + array[i] + ";" + rn +
					"     }" + rn +
					 rn +
					"     public void set" + Utils.upperFirstChar(array[i]) + "(String  " + array[i] + ") {" + rn +
					"	      this. " + array[i] + " = " + array[i] + ";" + rn +
					"     }" + rn ;
			}
			sb.append(bean);
		}
		String src =  
		"package " + currentBao + ".bean;" + rn +
		rn +
		"public class " + Utils.upperFirstChar(tableName) +"{"  + rn +
		 sb.toString() + rn +
		"}";
		
		
		String path  = System.getProperty("user.dir")+"/src/"+Utils.docToBackslash(currentBao)+"/bean/";
		File fpath = new File(path);
		if (!fpath.exists()) {
		   fpath.mkdirs();
	    }
		String fileName = System.getProperty("user.dir")+"/src/"+Utils.docToBackslash(currentBao)+"/bean/"+Utils.upperFirstChar(tableName)+".java";
		File f = new File(fileName);
		FileWriter fw = new FileWriter(f);
		fw.write(src);
		fw.flush();
		fw.close();
	}	
}
